package svc

import (
	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
	"go-exp/pkg/interceptor"
	"go-exp/zero/api/internal/config"
	"go-exp/zero/api/internal/middleware"
	"go-exp/zero/rpc/oauth/authrpc"
	"go-exp/zero/rpc/user/userrpc"
)

type ServiceContext struct {
	Config         config.Config
	OauthRpc       authrpc.AuthRpc
	UserRpc        userrpc.UserRpc
	AuthMiddleware rest.Middleware
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:         c,
		OauthRpc:       authrpc.NewAuthRpc(zrpc.MustNewClient(c.OAuthRpc, zrpc.WithUnaryClientInterceptor(interceptor.RpcAuthInterceptor()))),
		UserRpc:        userrpc.NewUserRpc(zrpc.MustNewClient(c.UserRpc, zrpc.WithUnaryClientInterceptor(interceptor.RpcAuthInterceptor()))),
		AuthMiddleware: middleware.NewAuthMiddleware(c).Handle,
	}
}
